package com.hnust.controller;

import com.hnust.domain.ClassInformation;
import com.hnust.service.ClassService;
import com.hnust.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/check")
public class ClassController {
    @Autowired
    private ClassService classService;

    @GetMapping("/getClassId")
    public String getClassId(@RequestParam("cla_name") String classname){
        String classId = classService.queryClassIdByClassName(classname);
        System.out.println(classId);
        return classId;
    }

    @GetMapping("/getClass")
    public Result<List<String>> getClasses(@RequestParam("tea_id") String tea_id, @RequestParam("testid") String testid){
        List<ClassInformation> classInformations = classService.queryClassByTestIDTeaId(tea_id, testid);
        List<String> classList = new ArrayList<String>();
        if(classInformations == null) return new Result<>(0,"无数据",null);
        else{
            for(ClassInformation cla : classInformations){
                String major = classService.queryMajorNameByClassId(cla.getClaId());
                String temp = cla.getGrade() + major + cla.getClaNumber() + "班";
                classList.add(temp);
            }
            System.out.println("classes = " + classInformations);
            System.out.println("获取各班具体情况成功 = " + classList);
            return  new Result<List<String>>(1,"获取各班具体情况成功",classList);
        }
    }
//    @GetMapping("/getClassId")
//    public String getClassId(@RequestParam("cla_name") String cla_name){
//        String classId =
//        return
//    }
}
